package wsi.dataguide.tree;

public class XmlObjectOccurrence {

	// init to 1 to avoid be printed
	private int min = 1;
	private int max = 1;
	private int all = 0;
	private double average = 1.;

	public void calculateAverage(int size) {
		average = 1. * all / size;
	}

	public double getAverage() {
		return average;
	}

	public int getMax() {
		return max;
	}

	public int getMin() {
		return min;
	}

	public void setAverage(double average) {
		this.average = average;
	}

	public void setMax(int max) {
		this.max = max;
	}

	public void setMin(int min) {
		this.min = min;
	}

	@Override
	public String toString() {
		return "[min=" + min + ", max=" + max + ", average=" + average + "]";
	}

	public String toXmlString() {
		StringBuilder sbuilder = new StringBuilder();

		if (max != 1)
			sbuilder.append(String.format(" %s:max=\"%d\"", WSXmlObject.PREFIX,
					max));

		if (min != 1)
			sbuilder.append(String.format(" %s:min=\"%d\"", WSXmlObject.PREFIX,
					min));

		if (average != 1.)
			sbuilder.append(String.format(" %s:avg=\"%.2f\"",
					WSXmlObject.PREFIX, average));

		return sbuilder.toString();
	}

	public void update(int occur) {
		if (occur < min)
			min = occur;

		if (occur > max)
			max = occur;

		all += occur;
	}

}
